package prictise.com.application1.cusview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;


/**
 * Created by cheng on 2018/1/30.
 */

public class OverlayImageView extends android.support.v7.widget.AppCompatImageView {
    private Drawable mOverlayDrawable;
    private int roundCorner;

    public OverlayImageView(Context context) {
        super(context);
    }

    public OverlayImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public OverlayImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setOverlayDrawable(Drawable drawable) {
        this.mOverlayDrawable = drawable;
    }


    @Override
    protected void onDraw(Canvas canvas) {
        try {
            super.onDraw(canvas);
            if (mOverlayDrawable != null) {
                Bitmap bp = ((BitmapDrawable)mOverlayDrawable).getBitmap();
                if (bp != null && !bp.isRecycled()) {
                    mOverlayDrawable.setBounds(0, 0, getWidth(), getHeight());
                    mOverlayDrawable.draw(canvas);
                } else {
                }
            }
        } catch (RuntimeException e) {
        }
    }

    public void setRoundCorner(int roundCorner) {
        this.roundCorner = roundCorner;
    }

    public int getRoundCorner() {
        return roundCorner;
    }
}
